package com.example.im.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.example.im.entity.FriendOrRoom;

import java.util.List;

@Dao
public interface FriendOrRoomDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    Long insert(FriendOrRoom friendOrRoom);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(List<FriendOrRoom> friendOrRooms);

    @Update(onConflict = OnConflictStrategy.REPLACE)
    void update(FriendOrRoom friendOrRoom);

    @Delete
    void delete(FriendOrRoom friendOrRoom);

    @Query("SELECT * FROM FriendOrRoom WHERE type =1")
    List<FriendOrRoom> selectFriends();

    @Query("SELECT * FROM FriendOrRoom WHERE type =2")
    List<FriendOrRoom> selectRooms();

    @Query("SELECT * FROM FriendOrRoom WHERE account= :account")
    FriendOrRoom selectFriendOrRoomByName(String account);


    @Query("SELECT * FROM FriendOrRoom WHERE account LIKE '%' || :search || '%' OR nick_name LIKE '%' || :search || '%' AND type = 2")
    List<FriendOrRoom>  selectFriendOrRoomBySearchRoom(String search);

    @Query("SELECT * FROM FriendOrRoom WHERE account LIKE '%' || :search || '%' OR nick_name LIKE '%' || :search || '%' AND type = 1")
    List<FriendOrRoom>  selectFriendOrRoomBySearchFriend(String search);

    @Query("SELECT * FROM FriendOrRoom WHERE account LIKE '%' || :search || '%' OR nick_name LIKE '%' || :search || '%'")
    List<FriendOrRoom> selectFriendOrRoomBySearch(String search);

    @Query("SELECT * FROM FriendOrRoom WHERE id= :id")
    FriendOrRoom selectFriendOrRoomById(int id);

}
